package org.example.chapter3_3.mapper;

import org.apache.ibatis.annotations.*;
import org.example.chapter3_3.entity.User;
import org.example.chapter3_3.entity.student;

import java.util.List;

//使用Mapper注释,让UserMapper变成Mybaits的映射器
@Mapper
public interface UserMapper {
    @Results(id = "usermap",value = {
            @Result(property = "name",column = "username"),
            @Result(property = "password",column = "password")
    })
    @Select("select * from user where username = #{username} and password =#{password}")
    User getUserByName(@Param("username") String name,String password);



    @Select({
            "<script>",
            "select * from tb_student where 1=1",
            "<if test='name != null'>",
            "and name = #{name}",
            "</if>",
            "<if test='no != null'>",
            "and no = #{no}",
            "</if>",
            "</script>"
    })
    List<student> getStuByNameOrNo(String name, String no);

    @Insert("insert into user(username,password) values (#{name},#{password})")
    int createUser(User user);
    //查找数据库中有多少条数据的用户名是${name}
    @Select("select count(1) from user where username = #{name}")
    int findUserByName(User user);
}

